<?php
//设置分页参数
		/*
		$page['paging']['pagesize'] = 10;
		$page['paging']['page']     = empty($app->get['page']) ? 1 : $app->get['page'];
		$page['paging']['offset']   = ($page['paging']['page'] - 1) * $page['paging']['pagesize'];		
		$page['paging']['state']    = 100;
		$page['paging']['strip']    = true;
		$page['paging']['total']    = $dao->getNewsCount($page['paging']);
		
		$page['list']  = $dao->getNewsAll($page['paging']);
		
		load("page"); //调用分页类
		//分页
		$clsPage = new Page($page['paging']['total'], $page['paging']['pagesize']);
		$page['paging']['pageshow'] = $clsPage->show();
		*/
class IndexAction{		
	
	function index()
	{
		global $app;
		$page = array();		
		$dao  = M("j_info");
		
		//栏目导航
		$sql = "select * from j_class order by j_order";
		$page['menu'] = $dao->query($sql);
		
		//正在时时更新
		$sql = "select a.id as j_readid,a.j_title as j_name,a.j_listurl,b.* from j_info a left join j_list b on b.id=a.j_listid order by a.id desc limit 1";
		$page['updating'] = $dao->query($sql, true);
		preg_match_all('/<a.+?href="(.+?)"[^>]*>/i', $page['updating']['j_item'], $out);
		$page['updating']['total'] = count($out[1]);
		$page['updating']['curr']  = count(explode(',', $page['updating']['j_pickstep']));
		
		//热门小说推荐
		$sql = "select * from j_list where j_state>=2 order by j_click desc limit 6";
		$page['hotlist'] = $dao->query($sql);
		
		//小说更新
		$sql = "select * from j_list where j_state>=2 and j_pickstep<>'' order by j_lastdate desc limit 25";
		$page['newlist'] = $dao->query($sql);
		foreach($page['newlist'] as &$v){
			$step = explode(',', $v['j_pickstep']);
			$step = explode(':', end($step));			
			$v['j_lastdate'] = date("m-d", $v['j_lastdate']);			
			$v['j_lasturl']  = $step[1];
			$v['j_lastid']   = $step[0];
			if( !empty($v['j_item']) && !empty($v['j_lasturl']) ){
				$reg = '/href="'.addcslashes($v['j_lasturl'],'/').'"[^>]*>(.+?)<\/a>/i';
				preg_match($reg, $v['j_item'], $out);
				$v['j_lastname'] = $out[1];	
			}	
		}		
		
		$app->assign('page',$page);
		
	}
	
	
}
?>